package com.example.exam.service.impl;

import com.example.exam.dao.SubjectiveDao;
import com.example.exam.entity.Subjective;
import com.example.exam.service.SubjectiveService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subjective)表服务实现类
 *
 * @author makejava
 * @since 2021-09-04 15:02:45
 */
@Service("subjectiveService")
public class SubjectiveServiceImpl implements SubjectiveService {
    @Resource
    private SubjectiveDao subjectiveDao;

    /**
     * 通过ID查询单条数据呀
     *
     * @param subid 主键
     * @return 实例对象
     */
    @Override
    public Subjective queryById(Integer subid) {
        return this.subjectiveDao.queryById(subid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Subjective> queryAllByLimit(int offset, int limit,String subquestion,String subject) {
        PageHelper.startPage(offset, limit);
        return this.subjectiveDao.queryAll3(subject,subquestion);
    }

    /**
     * 新增数据
     *
     * @param subjective 实例对象
     * @return 实例对象
     */
    @Override
    public Subjective insert(Subjective subjective) {
        this.subjectiveDao.insert(subjective);
        return subjective;
    }

    /**
     * 修改数据
     *
     * @param subjective 实例对象
     * @return 实例对象
     */
    @Override
    public Subjective update(Subjective subjective) {
        this.subjectiveDao.update(subjective);
        return this.queryById(subjective.getSubid());
    }

    /**
     * 通过主键删除数据
     *
     * @param subid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer subid) {
        return this.subjectiveDao.deleteById(subid) > 0;
    }

    @Override
    public List<Subjective> queryAll() {
        return this.subjectiveDao.queryAll2();
    }

    @Override
    public List<Subjective> queryBySubject(String subject) {
        return this.subjectiveDao.queryBySubject(subject);
    }

    @Override
    public List<Subjective> queryByChLike(String chquestion) {
        return this.subjectiveDao.queryByChLike(chquestion);
    }
}